package main

import (
	"github.com/labstack/echo"

	"shop_be/util"
	"shop_be/account"
	"shop_be/user"
	"shop_be/producter"

	"shop_be/order"
	"os"
	"shop_be/model"
	"encoding/json"
	"fmt"
)

func main() {

	util.Dbinit()

	app := echo.New()
	app.GET("/", func(c echo.Context) error {
		return c.String(200, "test success!!!")
	})

	exist, _ := PathExists("shop_be/")
	if !exist {
		os.MkdirAll("shop_be/", os.ModePerm)
	}

	app.Static("/static", "shop_be/")

	p := model.Order{}
	j, _ := json.Marshal(p)
	fmt.Println(string(j))

	account.AccountRouter(app)
	user.UserRouter(app)
	producter.ProducterRouter(app)
	order.OrderRouter(app)
	app.Start(":8080")
}

func PathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}
